package top.abilities.util.utils.Excel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author dong
 * @date 2020-06-22 10:13
 */
public class ExcelImport {
    private static Logger logger = LoggerFactory.getLogger(ExcelImport.class);

    public static Object readyGo(MultipartFile file, IExcelImport iExcelImport, Class aClass) {
        Object message = "";
        String fileName = file.getOriginalFilename();
        if (fileName == null || fileName.equals("")) {
            message = "上传文件不能为空！";
        }
        try {
            ExcelMapping excelMapping = new ExcelMapping(file.getInputStream(),
                    aClass);
            message = iExcelImport.doSomething(excelMapping);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("readyGo faild,", e);
        }
        return message;
    }

    public static void main(String[] args) {
        ExcelImport.readyGo(null, (object) -> {
            return object.toString();
        }, ExcelImport.class);
    }
}

